package com.lp.compt.controllers;

import org.springframework.web.bind.annotation.*;
import org.springframework.http.ResponseEntity;
import org.springframework.data.domain.Pageable;
import org.springframework.beans.factory.annotation.Autowired;
import com.lp.compt.pojo.SsKonwEntity;
import com.lp.compt.services.SsKonwEntityService;

import java.util.HashMap;
import java.util.Map;

/**
 * 服务类
 *
 * @author 刘前进 xindong888@163.com  www.xjke.com
 * @since 1.0.0
 */
@RestController
@CrossOrigin
@RequestMapping("/ssKonwEntity")
public class SsKonwEntityController {

    final
    SsKonwEntityService ssKonwEntityService;

    public SsKonwEntityController(SsKonwEntityService ssKonwEntityService) {
        this.ssKonwEntityService = ssKonwEntityService;
    }

    /**
     * 根据SsKonwEntity的字段,自动生成条件,字段的值为null不生成条件
     * http://localhost:8080/user/?id=1
     *
     * @param ssKonwEntity 实体对象
     * @param pageable     分页/排序对象
     * @return 返回的是实体, 里面涵盖分页信息及状态码
     */
    @GetMapping
    ResponseEntity<Object> search(SsKonwEntity ssKonwEntity, Pageable pageable) {
        return ssKonwEntityService.search(ssKonwEntity, pageable);
    }

    @PostMapping
    Map create(@RequestBody SsKonwEntity entity) {
        ssKonwEntityService.save(entity);
        return new HashMap() {{
            put("code", 200);
            put("msg", "添加成功");
        }};
    }

    @PutMapping
    void update() {
    }

    @DeleteMapping("/")
    void delete() {
    }
}
